From daf77bd5f1dfdd2d335a32a02ccae5507fbcfd75 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 22 Aug 2007 13:40:22 +0000 Subject: [PATCH] In ImageGallery: * Split "is parsing" and "respect bad images" concepts. * Call media handler parser hook * Use the $linkAttribs parameter instead of putting an tag around the whole media output. --- includes/CategoryPage.php | 2 +- includes/ImageGallery.php | 39 +++++++++++++++++++++++++++++++-------- includes/Parser.php | 3 ++- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/includes/CategoryPage.php b/includes/CategoryPage.php index 435a3f4b24..76a388a6e0 100644 --- a/includes/CategoryPage.php +++ b/includes/CategoryPage.php @@ -106,7 +106,7 @@ class CategoryViewer { $this->children_start_char = array(); if( $this->showGallery ) { $this->gallery = new ImageGallery(); - $this->gallery->setParsing(); + $this->gallery->setHideBadImages(); } } diff --git a/includes/ImageGallery.php b/includes/ImageGallery.php index 8d7c36d80f..0fe58bda09 100644 --- a/includes/ImageGallery.php +++ b/includes/ImageGallery.php @@ -20,9 +20,14 @@ class ImageGallery var $mRevisionId = 0; /** - * Is the gallery on a wiki page (i.e. not a special page) + * Hide blacklisted images? */ - var $mParsing; + var $mHideBadImages; + + /** + * Registered parser object for output callbacks + */ + var $mParser; /** * Contextual title, used when images are being screened @@ -42,14 +47,22 @@ class ImageGallery $this->mImages = array(); $this->mShowBytes = true; $this->mShowFilename = true; - $this->mParsing = false; + $this->mParser = false; + $this->mHideBadImages = false; } /** - * Set the "parse" bit so we know to hide "bad" images + * Register a parser object */ - function setParsing( $val = true ) { - $this->mParsing = $val; + function setParser( $parser ) { + $this->mParser = $parser; + } + + /** + * Set bad image flag + */ + function setHideBadImages( $flag = true ) { + $this->mHideBadImages = $flag; } /** @@ -238,7 +251,7 @@ class ImageGallery # We're dealing with a non-image, spit out the name and be done with it. $thumbhtml = "\n\t\t\t".'
' . htmlspecialchars( $nt->getText() ) . '
'; - } elseif( $this->mParsing && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() ) ) { + } elseif( $this->mHideBadImages && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() ) ) { # The image is blacklisted, just show it as a text link. $thumbhtml = "\n\t\t\t".'
' . $sk->makeKnownLinkObj( $nt, htmlspecialchars( $nt->getText() ) ) . '
'; @@ -248,8 +261,18 @@ class ImageGallery . htmlspecialchars( $img->getLastError() ) . ''; } else { $vpad = floor( ( 1.25*$this->mHeights - $thumb->height ) /2 ) - 2; + $linkAttribs = array( + 'title' => $nt->getPrefixedText(), + 'href' => $nt->getLocalURL(), + ); + $thumbhtml = "\n\t\t\t".'
' - . $sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . '
'; + . $thumb->toHtml( array(), $linkAttribs ) . ''; + + // Call parser transform hook + if ( $this->mParser && $img->getHandler() ) { + $img->getHandler()->parserTransformHook( $this->mParser, $img ); + } } //TODO diff --git a/includes/Parser.php b/includes/Parser.php index 9f79d6711e..da8d512f0f 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -4411,7 +4411,8 @@ class Parser $ig->setContextTitle( $this->mTitle ); $ig->setShowBytes( false ); $ig->setShowFilename( false ); - $ig->setParsing(); + $ig->setParser( $this ); + $ig->setHideBadImages(); $ig->setAttributes( Sanitizer::validateTagAttributes( $params, 'table' ) ); $ig->useSkin( $this->mOptions->getSkin() ); $ig->mRevisionId = $this->mRevisionId; -- 2.20.1